﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PdfLibrary
{
    public class PdfName : IPdfObject
    {
        public string Value;

        public bool LoadFromReader(PdfReader reader, bool throwException)
        {
            this.Value = GetValueFromReader(reader, throwException);
            return this.Value != null;
        }

        public static string GetValueFromReader(PdfReader reader, bool throwException = false)
        {
            if (!reader.TryReadToken("/"))
                if (throwException)
                    throw new PdfParsingException(reader, "PdfName start tag (/) not found!");
                else
                    return null;

            string value = reader.ReadWord();

            if (value == "")
                throw new PdfParsingException(reader, "PdfName is empty!");

            return value;
        }
    }
}
